/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainPanel2.java
 *
 * Created on 2009-3-25, 2:12:03
 */
package com.modudf;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.modudf.common.FileUtils;
import com.modudf.common.SwingAnimation;

public class MainPanel2 extends javax.swing.JPanel {

    private JFrame j;

    /** Creates new form MainPanel2 */
    public MainPanel2(JFrame j) {
        this.j = j;
        initComponents();
        initMyListener();
        initCheckState();
        initHelp();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        message = new javax.swing.JLabel();
        flagTomcat = new javax.swing.JLabel();
        flagMySQL = new javax.swing.JLabel();
        flagMySQLMessage = new javax.swing.JLabel();
        flagTomcatMessage = new javax.swing.JLabel();
        jPanel_process = MyPanel.getImage("loading.gif");
        jLayeredPane2 = new javax.swing.JLayeredPane();
        jLabel1 = new javax.swing.JLabel();
        jb_submit = new javax.swing.JButton();
        jl_tomcat_info = new javax.swing.JLabel();
        jtf_port = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtf_name = new javax.swing.JTextField();
        jLayeredPane3 = new javax.swing.JLayeredPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jta_help = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204), 5));

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jLayeredPane1.setName("jLayeredPane1"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setOpaque(false);

        jButton1.setLabel("启动(调试模式)");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("启动(服务模式)");
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setLabel("卸载(系统服务)");
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addGap(18, 18, 18)
                .addComponent(jButton3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBounds(0, 10, 137, 125);
        jLayeredPane1.add(jPanel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        message.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        message.setText("......................");
        message.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        message.setFocusable(false);
        message.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        message.setName("message"); // NOI18N
        message.setBounds(10, 140, 220, 23);
        jLayeredPane1.add(message, javax.swing.JLayeredPane.DEFAULT_LAYER);

        flagTomcat.setBackground(new java.awt.Color(204, 204, 204));
        flagTomcat.setForeground(new java.awt.Color(204, 204, 204));
        flagTomcat.setMaximumSize(new java.awt.Dimension(15, 15));
        flagTomcat.setMinimumSize(new java.awt.Dimension(15, 15));
        flagTomcat.setName("flagTomcat"); // NOI18N
        flagTomcat.setOpaque(true);
        flagTomcat.setPreferredSize(new java.awt.Dimension(15, 15));
        flagTomcat.setRequestFocusEnabled(false);
        flagTomcat.setVerifyInputWhenFocusTarget(false);
        flagTomcat.setBounds(160, 30, 15, 10);
        jLayeredPane1.add(flagTomcat, javax.swing.JLayeredPane.DEFAULT_LAYER);

        flagMySQL.setBackground(new java.awt.Color(204, 204, 204));
        flagMySQL.setForeground(new java.awt.Color(204, 204, 204));
        flagMySQL.setMaximumSize(new java.awt.Dimension(15, 15));
        flagMySQL.setMinimumSize(new java.awt.Dimension(15, 15));
        flagMySQL.setName("flagMySQL"); // NOI18N
        flagMySQL.setOpaque(true);
        flagMySQL.setPreferredSize(new java.awt.Dimension(15, 15));
        flagMySQL.setRequestFocusEnabled(false);
        flagMySQL.setVerifyInputWhenFocusTarget(false);
        flagMySQL.setBounds(160, 60, 16, 10);
        jLayeredPane1.add(flagMySQL, javax.swing.JLayeredPane.DEFAULT_LAYER);

        flagMySQLMessage.setText("未运行");
        flagMySQLMessage.setName("flagMySQLMessage"); // NOI18N
        flagMySQLMessage.setBounds(190, 50, 90, 30);
        jLayeredPane1.add(flagMySQLMessage, javax.swing.JLayeredPane.DEFAULT_LAYER);

        flagTomcatMessage.setText("未运行");
        flagTomcatMessage.setName("flagTomcatMessage"); // NOI18N
        flagTomcatMessage.setBounds(190, 20, 90, 30);
        jLayeredPane1.add(flagTomcatMessage, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanel_process.setVisible(false);
        jPanel_process.setName("jPanel_process"); // NOI18N

        javax.swing.GroupLayout jPanel_processLayout = new javax.swing.GroupLayout(jPanel_process);
        jPanel_process.setLayout(jPanel_processLayout);
        jPanel_processLayout.setHorizontalGroup(
            jPanel_processLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 51, Short.MAX_VALUE)
        );
        jPanel_processLayout.setVerticalGroup(
            jPanel_processLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 41, Short.MAX_VALUE)
        );

        jPanel_process.setBounds(240, 120, 51, 41);
        jLayeredPane1.add(jPanel_process, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTabbedPane1.addTab("MODUDF主面板", jLayeredPane1);

        jLayeredPane2.setName("jLayeredPane2"); // NOI18N

        jLabel1.setText("Tomcat端口（默认8080）：");
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.setBounds(10, 20, 150, 20);
        jLayeredPane2.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jb_submit.setText("修改");
        jb_submit.setName("jb_submit"); // NOI18N
        jb_submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_submitActionPerformed(evt);
            }
        });
        jb_submit.setBounds(170, 100, 100, 23);
        jLayeredPane2.add(jb_submit, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jl_tomcat_info.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jl_tomcat_info.setText("注意：修改端口之后需要重新启动Tomcat");
        jl_tomcat_info.setName("jl_tomcat_info"); // NOI18N
        jl_tomcat_info.setBounds(10, 140, 300, 30);
        jLayeredPane2.add(jl_tomcat_info, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jtf_port.setName("jtf_port"); // NOI18N
        jtf_port.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtf_portActionPerformed(evt);
            }
        });
        jtf_port.setBounds(170, 20, 100, 21);
        jLayeredPane2.add(jtf_port, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel6.setText(" 默认项目 ：");
        jLabel6.setName("jLabel6"); // NOI18N
        jLabel6.setBounds(80, 60, 80, 20);
        jLayeredPane2.add(jLabel6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jtf_name.setText("/modudf");
        jtf_name.setName("jtf_name"); // NOI18N
        jtf_name.setBounds(170, 60, 100, 21);
        jLayeredPane2.add(jtf_name, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTabbedPane1.addTab("Tomcat配置", jLayeredPane2);

        jLayeredPane3.setName("jLayeredPane3"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jta_help.setColumns(20);
        jta_help.setEditable(false);
        jta_help.setLineWrap(true);
        jta_help.setRows(5);
        jta_help.setDragEnabled(true);
        jta_help.setName("jta_help"); // NOI18N
        jScrollPane1.setViewportView(jta_help);

        jScrollPane1.setBounds(-4, -4, 310, 180);
        jLayeredPane3.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTabbedPane1.addTab("问题及帮助", jLayeredPane3);

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/modudf/resources/exit.jpg"))); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel2MouseClicked(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Basemic Symbol", 3, 22)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(104, 129, 160));
        jLabel3.setText("MODUDF-v1.0 ");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/modudf/resources/modudf_logo.png"))); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Arial Black", 3, 18)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(204, 204, 204));
        jLabel5.setText("www.seadata.com.cn");
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 134, Short.MAX_VALUE)
                        .addComponent(jLabel2))
                    .addComponent(jLabel5))
                .addContainerGap())
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)))
                .addGap(17, 17, 17))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, Short.MAX_VALUE)
                .addGap(42, 42, 42))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap(77, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
                .addGap(10, 10, 10))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked
        this.j.setVisible(false);
        this.j.setAlwaysOnTop(false);
}//GEN-LAST:event_jLabel2MouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // Start mysql and tomcat
        this.j.setAlwaysOnTop(true);
        SwingAnimation animation = new SwingAnimation(j, 300);
        animation.flyToRB();
        jPanel_process.setVisible(true);
        message.setForeground(Color.BLACK);
        message.setText("正在启动JavaEE及web应用!");
        new Thread(new Runnable() {

            public void run() {
                boolean mOK = false;
                boolean tOK = false;
                StringBuilder sb = new StringBuilder();
                if (MySQL.isRunning()) {
                    sb.append("MySQL正在运行中.");
                    mOK = true;
                } else {
                    mOK = MySQL.startup();
                    if (mOK) {
                        sb.append("MySQL正常启动.");
                    } else {
                        sb.append("MySQL启动出错!稍后重试或重启电脑.");
                    }
                }
                if (Tomcat.isRunning()) {
                    sb.append("Tomcat正在运行中.");
                    tOK = true;
                } else {
                    Tomcat.reloadPort();
                    tOK = Tomcat.startup();
                    if (tOK) {
                        sb.append("Tomcat已经启动.");
                    } else {
                        sb.append("Tomcat启动出错,稍后重试或重启电脑.");
                    }
                }
                if (mOK && tOK) {
                    setDefaultPage();
                    CMD.openURL(defaultPage);
                } else {
                    message.setText(sb.toString());
                    message.setForeground(Color.RED);
                }
                jPanel_process.setVisible(false);
            }
        }).start();
}//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // Install windows service
        this.j.setAlwaysOnTop(true);
        SwingAnimation animation = new SwingAnimation(j, 300);
        animation.flyToRB();
        jPanel_process.setVisible(true);
        message.setForeground(Color.BLACK);
        message.setText("正在注册系统服务");
        new Thread(new Runnable() {

            public void run() {
                boolean isOK = true;
                String msg = null;
                if (MySQL.isRunning() || Tomcat.isRunning()) {
                    msg = "系统运行中,请停止后再注册.";
                    isOK = false;
                } else if (!MySQL.serviceInstall() || !Tomcat.serviceInstall()) {
                    msg = "注册系统服务时出错！";
                    isOK = false;
                }
                if (isOK) {
                    Tomcat.reloadPort();
                    setDefaultPage();
                    CMD.openURL(defaultPage);
                } else {
                    message.setForeground(Color.RED);
                    message.setText(msg);
                }
                jPanel_process.setVisible(false);
            }
        }).start();
}//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // Uninstall windows service
        jPanel_process.setVisible(true);
        message.setForeground(Color.BLACK);
        message.setText("正在注销系统服务!");
        new Thread(new Runnable() {

            public void run() {
                boolean mOK = MySQL.serviceRemove();
                boolean tOK = Tomcat.serviceRemove();
                StringBuilder sb = new StringBuilder();
                if (!mOK || !tOK) {
                    sb.append("服务已注销或不存在,如果仍有问题,请重启电脑.");
                }
                if (mOK && tOK) {
                    message.setText("系统服务已经注销!");
                    message.setForeground(GREEN);
                } else {
                    message.setText(sb.toString());
                    message.setForeground(Color.RED);
                }
                jPanel_process.setVisible(false);
            }
        }).start();
}//GEN-LAST:event_jButton3ActionPerformed

    private void jb_submitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_submitActionPerformed
        final boolean isRunning = Tomcat.isRunning();
        final String port = this.jtf_port.getText();
        try {
            if (Integer.parseInt(port) < 1 || Integer.parseInt(port) >= 65535) {
                JOptionPane.showMessageDialog(this.j,
                        "错误的端口号，请填写1-65535以内的数字");
            }
        } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(this.j,
                    "错误的端口号，请填写1-65535以内的数字");
            return;
        }
        new Thread(new Runnable() {

            public void run() {
                jl_tomcat_info.setForeground(Color.BLACK);
                jl_tomcat_info.setText("正在修改...");
                if (Tomcat.editPort(port)) {
                    if (isRunning) {
                        jl_tomcat_info.setForeground(GREEN);
                        jl_tomcat_info.setText("修改成功，" +
                                "你需要重新启动才能使设置生效。");
                    } else {
                        jl_tomcat_info.setForeground(GREEN);
                        jl_tomcat_info.setText("修改成功。");
                    }
                } else {
                    jl_tomcat_info.setForeground(Color.RED);
                    jl_tomcat_info.setText("修改端口时出错！");
                }
            }
        }).start();
}//GEN-LAST:event_jb_submitActionPerformed

    private void jtf_portActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_portActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtf_portActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel flagMySQL;
    private javax.swing.JLabel flagMySQLMessage;
    private javax.swing.JLabel flagTomcat;
    private javax.swing.JLabel flagTomcatMessage;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JLayeredPane jLayeredPane3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel_process;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton jb_submit;
    private javax.swing.JLabel jl_tomcat_info;
    private javax.swing.JTextArea jta_help;
    private javax.swing.JTextField jtf_name;
    private javax.swing.JTextField jtf_port;
    private javax.swing.JLabel message;
    // End of variables declaration//GEN-END:variables

    private void initMyListener() {
        new Thread(new Runnable() {

            public void run() {
                while (true) {
                    if (Tomcat.isRunning()) {
                        flagTomcat.setBackground(GREEN);
                        flagTomcatMessage.setText("Tomcat(" + Tomcat.getPort() + ")");
                    } else {
                        flagTomcat.setBackground(Color.GRAY);
                        flagTomcatMessage.setText("Tomcat(已停止)");
                    }
                    if (MySQL.isRunning()) {
                        flagMySQL.setBackground(GREEN);
                        flagMySQLMessage.setText("MySQL(3306)");
                    } else {
                        flagMySQL.setBackground(Color.GRAY);
                        flagMySQLMessage.setText("MySQL(已停止)");
                    }
                    try {
                        Thread.sleep(1000 * 3);
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                        Logger.getLogger(CMD.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }).start();
    }

    private void initCheckState() {
        if (Tomcat.isRunning() || MySQL.isRunning()) {
            setDefaultPage();
        }
        this.jtf_port.setText(String.valueOf(Tomcat.getPort()));
    }

    private void initHelp() {
        try {
            String helpMessage = FileUtils.getInstance().read(new File("help.txt"), "utf-8");
            this.jta_help.setText(helpMessage);
        } catch (Exception e) {
            this.jta_help.setText("找不到文件help.txt");
        }
    }

    private void setDefaultPage() {
        defaultPage = "http://localhost:" + Tomcat.getPort() + this.jtf_name.getText();
        message_underline = "<html><u>主页 " + defaultPage + "</u></html>";
        message_underline_no = "主页 " + defaultPage;
        message.setText(message_underline_no);
        message.setForeground(Color.BLUE);
        if (message_mouseAdapter == null) {
            message_mouseAdapter = new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    CMD.openURL(defaultPage);
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                    message.setText(message_underline);
                    message.setForeground(Color.PINK);
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    setCursor(Cursor.getDefaultCursor());
                    message.setText(message_underline_no);
                    message.setForeground(Color.BLUE);
                }
            };
            message.addMouseListener(message_mouseAdapter);
        }
    }
    private final static Color GREEN = new Color(13, 158, 20);
    private String message_underline;
    private String message_underline_no;
    private MouseAdapter message_mouseAdapter;
    private String defaultPage;
}
